import JsonData from "../../Json.js";
let { brideName, groomName, sharePhoto} = JsonData.invite;
Page({
  data: {
    isShowSaveBtn: "none",
    momentContent: "",
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    circular: false,
    current: 0
  },
  changeIndicatorDots: function() {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    });
  },
  changeAutoplay: function() {
    this.setData({
      autoplay: !this.data.autoplay
    });
  },
  intervalChange: function(e) {
    this.setData({
      interval: e.detail.value
    });
  },
  durationChange: function(e) {
    this.setData({
      duration: e.detail.value
    });
  },
  onLoad: function(options) {
    console.log(JSON.parse(options.data));
    this.setData({
      momentContent: JSON.parse(options.data),
      current: JSON.parse(options.currentId)
    });
  },
  onReady: function() {},
  onShow: function() {
    if (this.data.momentContent[0].momentId === 6) {
      this.setData({
        isShowSaveBtn: "block"
      });
    }
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function (e) {
    return "button" === e.from && console.log(e.target), {
      title: `${brideName}&${groomName}的结婚邀请函`,
      path: "pages/index/index",
      imageUrl: sharePhoto,
      success: function (res) {
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (err) {
        console.log("转发失败:" + JSON.stringify(err));
      }
    };
  },
  backMomentPage: function() {
    wx.navigateTo({
      url: "../moments/moments"
    });
  },
  savePhoto: function() {
    wx.getImageInfo({
      src: "../../images/shareMoments.jpg",
      success: function(res) {
        res.errMsg === "getImageInfo:ok" && wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success: function(res) {
            wx.showToast({
              title: "保存图片成功"
            });
          },
          fail: function(err) {
            wx.showToast({
              title: "保存图片失败",
              icon: "none"
            });
          }
        });
      }
    });
  }
});